<template>
  <el-tabs v-model="activeName" v-loading="loading" type="border-card" @tab-click="clickMenu">
    <el-tab-pane v-for="(item, key) in childMenuTabs" :key="key" :lazy="true" :label="$t(item.menuName)" :name="item.menuName">
      <!--动态页面 ，根据is的值来确定渲染哪个组件 -->
      <component :is="menuPath" ref="menuPath" :listed-id="listedId" :deal-id="dealId" />
    </el-tab-pane>
  </el-tabs>
</template>
<script>
import { childMenuList	} from '@/api/system/menu'
import { getAsyncComponent } from '@/utils'

export default {
  props: {
    listedId: {
      type: String,
      default: ''
    },
    dealId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      // 加载
      loading: true,
      // 选中页签名称
      activeName: this.$t('基本信息'),
      // 项目ID
      // companyId: this.$route.query.companyId,
      // 子页签
      childMenuTabs: [],
      // 组件地址
      menuPath: '',
      // 参数
      parameter: {
        listedId: this.listedId,
        dealId: this.dealId
      },
      // 菜单标识
      menuIdent: 'listed_deal_base'
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    listLoad() {
      this.loading = true
      // 菜单列表
      childMenuList(this.menuIdent).then(response => {
        this.childMenuTabs = response.rows
        this.clickMenu(response.rows[0])
        if (response.rows[0] !== undefined && response.rows[0] !== null && response.rows[0] !== '') {
          this.activeName = this.$t(response.rows[0].menuName)
        } else {
          this.loading = false
          return this.msgError(this.$t('菜单无权限'))
        }
        this.loading = false
      })
    },
    clickMenu(tab) {
      this.childMenuTabs && this.childMenuTabs.forEach(item => {
        if (item.menuName === tab.menuName || item.menuName === tab.name) {
          this.$nextTick(() => {
            this.importFormPath(item.component)
          })
        }
      })
      this.listComponent()
    },
    listComponent() {
      this.$bus.$once('async_done', () => {
        this.load()
      })
    },
    load() {
      if (this.$refs.menuPath?.init !== undefined) {
        const data = {
          id: this.listedId
        }
        this.$refs.menuPath.init(data)
        this.$refs.menuPath.openLocation = 'Home'
      }
    },
    // 引入组件
    importFormPath(menuPath) {
      if (menuPath) {
        this.menuPath = getAsyncComponent('@/views/' + menuPath)
      } else {
        const error = 'error/404'
        this.importFormPath(error)
      }
    }
  }
}
</script>
